# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

class Solution:
    def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode:
        a_pre = list1
        while a > 1:
            a_pre = a_pre.next
            a -= 1

        b_nxt = list1
        while b > -1:
            b_nxt = b_nxt.next
            b -= 1

        a_pre.next = list2
        tail_2 = list2
        while tail_2.next:
            tail_2 = tail_2.next
        tail_2.next = b_nxt
        return list1
